var _ = require('lodash')
var Page = (function () {
  function Page (obj) {
    console.log('comming obj:', obj)
    this.dbInfo = obj.dbInfo ? obj.dbInfo : {}
    this.groupId = obj.groupId ? obj.groupId : -1
    this.matirials = obj.matirials ? obj.matirials : obj.items ? obj.items : []
    const defaultPageStyle = { // todo 这里和下面的组件初始化可以放一起，抽离出来使用
      style: {
        height: '736',
        backgroundColor: '',
        borderWidth: '',
        borderStyle: '',
        borderRadius: '',
        borderColor: ''
      },
      title: '请输入页面标题'
    }
    this.pageInfo = obj.pageInfo ? obj.pageInfo : defaultPageStyle
  }

  Page.prototype.addMatirial = function (obj) {
    this.matirials.push(new Matirial(obj))
  }

  Page.prototype.removeMatirial = function (o) {
    _.remove(this.matirials, function (item) {
      if (typeof (o) === 'number') {
        return item.position === o
      } else {
        return item.position === o.position
      }
    })
  }

  Page.prototype.dbName = 'page'

  return Page
})()

var Matirial = (function () {
  function Matirial (obj) {
    if (!obj) obj = { style: {} }
    this.type = obj.type ? obj.type : 'v-label'
    this.position = obj.position ? obj.position : 1
    this.src = obj.src ? obj.src : '/'
    this.style = {
      color: obj.style.color ? obj.style.color : 'rgba(19, 206, 102, 0.8)',
      font: obj.style.font ? obj.style.font : '微软雅黑',
      fontSize: obj.style.fontSize ? obj.style.fontSize : '20',
      opacity: obj.style.opacity ? obj.style.opacity : 100,
      transform: obj.style.transform ? obj.style.transform : 'rotate(deg)',
      top: obj.style.top ? obj.style.top : '10',
      left: obj.style.left ? obj.style.left : '10',
      textAlign: obj.style.textAlign ? obj.style.textAlign : 'center',
      width: obj.style.width ? obj.style.width : '',
      height: obj.style.height ? obj.style.height : '',
      borderWidth: obj.style.borderWidth ? obj.style.borderWidth : '',
      borderColor: obj.style.borderColor ? obj.style.borderColor : '',
      borderStyle: obj.style.borderStyle ? obj.style.borderStyle : '',
      backgroundColor: obj.style.backgroundColor ? obj.style.backgroundColor : '',
      borderRadius: obj.style.borderRadius ? obj.style.borderRadius : ''
    }
    this.text = obj.text ? obj.text : '新建标签'
    this.editting = false
  }

  Matirial.prototype.dbName = 'matirial'
  return Matirial
})()

module.exports = { Matirial: Matirial, Page: Page }
